package com.gmail.avereshchaga.db.service;

import com.gmail.avereshchaga.db.dao.IInvoiceDAO;
import com.gmail.avereshchaga.db.entity.IInvoice;
import java.util.Date;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 *
 * @author <a href="mailto:avereshchaga@gmail.com">Vereshchaga Alexey</a>
 */
@Service
public class InvoiceServiceImpl implements IInvoiceService {

    @Autowired
    private IInvoiceDAO invoiceDAO;

    @Transactional
    @Override
    public IInvoice createInvoice(IInvoice invoice) {
        invoiceDAO.createInvoice(invoice);
        return invoice;
    }

    @Transactional
    @Override
    public void updateInvoice(IInvoice invoice) {
        invoiceDAO.updateInvoice(invoice);
    }

    @Transactional
    @Override
    public IInvoice deleteInvoice(IInvoice invoice) {
        invoiceDAO.deleteInvoice(invoice);
        return invoice;
    }

    @Transactional
    @Override
    public List<IInvoice> findAll(Integer page) {
        return invoiceDAO.findAll(page);
    }

    @Transactional
    @Override
    public IInvoice findById(Long id) {
        return invoiceDAO.findById(id);
    }

    @Transactional
    @Override
    public List<IInvoice> findByFilter(Date date, String name, Integer page) {
        return invoiceDAO.findByFilter(date, name, page);
    }

    @Transactional
    @Override
    public List<IInvoice> findByName(String name, Integer page) {
        return invoiceDAO.findByName(name, page);
    }
}
